#define _CRT_SECURE_NO_WARNINGS
#include"queue.h"


AnimalShelf* animalShelfCreate() {
    AnimalShelf* new = (AnimalShelf*)malloc(sizeof(AnimalShelf));
    new->head = new->tail = NULL;
    new->quantity = 0;
    return new;
}

void animalShelfEnqueue(AnimalShelf* obj, int* animal, int animalSize) {
    k* new = (k*)malloc(sizeof(k));
    if (new == NULL) {
        printf("malloc failure\n");
        exit(-1);
    }
    if (obj->quantity >= 20000)
        return;
    else {
        new->a = animal[0];
        new->b = animal[1];
        new->next = NULL;
        if (obj->head == NULL) {
            obj->head =obj->tail= new;
            obj->quantity++;
        }
        else {
            obj->tail->next = new;
            obj->tail = obj->tail->next;
            obj->quantity++;
        }
    }
}

int* animalShelfDequeueAny(AnimalShelf* obj, int* retSize) {
    if (obj->head == NULL)
    {
        int* a = (int*)malloc(2 * sizeof(int));
        a[0] = -1;
        a[1] = -1;
        return a;
    }
    int* a = (int*)malloc(2 * sizeof(int));
    a[0] = obj->head->a;
    a[1] = obj->head->b;
    obj->quantity--;
    k* new = obj->head->next;
    free(obj->head);
    obj->head = new;
    return a;
}

int* animalShelfDequeueDog(AnimalShelf* obj, int* retSize) {
    k* new = obj->head;
    int* a = (int*)malloc(2 * sizeof(int));
    a[0] = -1;
    a[1] = -1;
    while (new != NULL) {
        if (new->b == 1)
        {
            a[0] = new->a;
            a[1] = new->b;
            return a;
        }
        new = new->next;
    }
    return a;
}

int* animalShelfDequeueCat(AnimalShelf* obj, int* retSize) {
    k* new = obj->head;
    int* a = (int*)malloc(2 * sizeof(int));
    a[0] = -1;
    a[1] = -1;
    while (new != NULL) {
        if (new->b == 0)
        {
            a[0] = new->a;
            a[1] = new->b;
            return a;
        }
        new = new->next;
    }
    return a;
}

void animalShelfFree(AnimalShelf* obj) {
    k* new = obj->head;
    while (new != NULL) {
        k* x = new->next;
        free(new);
        new = x;
    }
    free(obj);
    obj = NULL;
}
int firstUniqChar(char* s) {
    int size = strlen(s);
    int a[256] = { 0 };
    int x = 0;
    for (int i = 0; i < size; i++) {
        a[(unsigned char)s[i]]++;
    }
    for (int i = 0; i < size; i++) {
        if (a[(unsigned char)s[i]] == 1)
            return i;
    }
    return -1;
}